<!DOCTYPE html>
<html lang="en">

<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <meta http-equiv="X-UA-Compatible" content="ie=edge">
    <title>Document</title>
    <style>
        div{
            width: 400px;
            height: 60px;
            margin: 100px auto;
            background-color:pink;
        }
        span{
            display: inline-block;
            width: 80px;
            height: 50px;
            font-size: 16px;
            text-align: center;
            color: red;
            line-height: 50px;
        }
    </style>
</head>

<body>
    <div>
        商品秒杀倒计时
        <span class="h">00小时</span>
        <span class="m">00分钟</span>
        <span class="s">00秒</span>

    </div>

    <script>
           const spanHObj = document.querySelector(".h")
           const spanMObj = document.querySelector(".m")
           const spanSObj = document.querySelector(".s")

           //商品的秒杀时间
           const createTime = new Date("2023-12-2 21:00:00")

           //计算出：商品的秒杀时间距离当前时间还有多久
           function payment(){
               const currentTime = new Date();
               const timeSecond = (createTime-currentTime)/1000;
               //计算出小时
               let h = parseInt(timeSecond/60/60%24)        //这个是保证是24小时以内，去掉就是24小时以上
               spanHObj.innerHTML = h+"小时";

               //计算分钟
               let m = parseInt(timeSecond/60%60)
               spanMObj.innerHTML = m+"分钟";

               //计算秒
               let s = parseInt(timeSecond%60)  
               spanSObj.innerHTML = s+"秒";
           }

           //加上计时器
           setInterval(payment,1000)
           setInterval(payment(),1000)
    </script>
</body>

</html>